package com.imooc.demo;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName HelloScheduler
 * @Description TODO
 * @Author Wxg
 * @Date 2018/11/13 18:08
 * @Version 1.0
 */
public class HelloSchedulerV2 {
    public static void main(String[] args) throws SchedulerException {
        JobDetail jobDetail = JobBuilder.newJob(HelloJobV2.class)
                .withIdentity("myJob", "group1")
                .usingJobData("message", "hello myJob1")
                .usingJobData("FloatJobValue", 3.14F)
                .build();

        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("myTrigger", "group1")
                .usingJobData("message", "hello myTrigger1")
                .usingJobData("DoubleTriggerValue", 2.0D)
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(2).repeatForever())
                .build();

        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
        scheduler.start();

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("Current Exec Time is : " + sdf.format(date));

        scheduler.scheduleJob(jobDetail, trigger);
    }
}
